package com.yingdong.logic.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.yingdong.db.Usermotion;
import com.yingdong.logic.domain.GameUser;
import com.yingdong.message.MotionMessage;

public class MotionController extends GameController {
	private Map<Integer, Usermotion> motionMap = new ConcurrentHashMap<>();

	public MotionController(GameUser user) {
		super(user);

	}

	@Override
	public void init() {
		List<Usermotion> list = Usermotion.getInstance().selectObjectsByCondition("userId", getUserId());
		for (Usermotion usermotion : list) {
			motionMap.put(usermotion.getActionId(), usermotion);
		}
	}

	@Override
	public void firstEnter() {
		new MotionMessage(motionMap.values()).sendToClient(getSessionId());
	}

	@Override
	public void saveDB() {
		Usermotion.getInstance().saveBatch(motionMap.values());
	}

}
